package com.gdziarmaga.webshop.delivery.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import com.gdziarmaga.webshop.book.model.Book;

@Embeddable
@Entity
@Table(name = "Book_Delivery")
public class BookDelivery {

	private long book_delivery_id;
	private Book book;
	private Delivery delivery;
	private Integer number_of_delivered_books;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "book_delivery_seq")
	@SequenceGenerator(name = "book_delivery_seq", sequenceName = "BOOK_DELIVERY_SEQ")
	@Column(name = "book_delivery_id", precision = 20, scale = 0, unique = true)
	public long getBook_delivery_id() {
		return book_delivery_id;
	}

	public void setBook_delivery_id(long book_delivery_id) {
		this.book_delivery_id = book_delivery_id;
	}

	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn(name = "book_id")
	public Book getBook() {
		return book;
	}

	public void setBook(Book book) {
		this.book = book;
	}

	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn(name = "delivery_id")
	public Delivery getDelivery() {
		return delivery;
	}

	public void setDelivery(Delivery delivery) {
		this.delivery = delivery;
	}

	public void setNumber_of_delivered_books(Integer number_of_delivered_books) {
		this.number_of_delivered_books = number_of_delivered_books;
	}

	@Column(name = "number_of_delivered_books", precision = 20, scale = 0, nullable=true)
	public Integer getNumber_of_delivered_books() {
		return number_of_delivered_books;
	}

}
